home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 20
/
Cream of the Crop 20 (Terry Blount) (1996).iso
/
program
/
vol15n10.zip
/
MULTIL.ZIP
/
MLSRC.ZIP
/
MSDEV
/
PROJECTS
/
MLAUNCH
/
MLPAGE.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-05-04
|
5KB
|
178 lines
// MLPage.cpp : implementation file
//
#include "stdafx.h"
#include "MFCML.h"
#include "MLPage.h"
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// Forward references
CString GetFilenameExtension(CString);
void CreateRegValue(HKEY, CString, CString);
HKEY CreateRegKey(CString, CString);
/////////////////////////////////////////////////////////////////////////////
// CMLPage property page
IMPLEMENT_DYNCREATE(CMLPage, CPropertyPage)
CMLPage::CMLPage() : CPropertyPage(CMLPage::IDD)
{
pRegistryKey = NULL;
m_bOpenDialog = FALSE;
m_bAboutDialog = FALSE;
//{{AFX_DATA_INIT(CMLPage)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
CMLPage::~CMLPage()
{
if (pRegistryKey != NULL)
delete pRegistryKey;
}
void CMLPage::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMLPage)
DDX_Control(pDX, IDC_LISTBOX, m_ListBox);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMLPage, CPropertyPage)
//{{AFX_MSG_MAP(CMLPage)
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_BN_CLICKED(IDC_DELETE, OnDelete)
ON_BN_CLICKED(IDC_ABOUTBOX, OnAboutbox)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// Set internal filename
void CMLPage::SetFilename(LPCSTR szShellFilename)
{
// Initialize the CRegistryKey object with the registry entries
CString strKey;
strFilename = szShellFilename;
strKey = GetFilenameExtension(strFilename) + "\\MultiLaunch";
// Construct the RegistryKey object
pRegistryKey = new CRegistryKey(strKey);
}
/////////////////////////////////////////////////////////////////////////////
// CMLPage message handlers
// Handle user clicking on the CANCEL button of the property sheet
void CMLPage::OnCancel()
{
CPropertyPage::OnCancel();
}
// Initialize the Property Page listbox
BOOL CMLPage::OnInitDialog()
{
// Add registry entries to the listbox
CRegistryValue* pRegistryValue;
CListBox* pLB = (CListBox*)GetDlgItem(IDC_LISTBOX);
while (pRegistryKey->GetNext(pRegistryValue))
pLB->AddString(pRegistryValue->m_strName);
return CDialog::OnInitDialog();
}
// Delete an association from the registry
void CMLPage::OnDelete()
{
HKEY hKey;
CString strKey;
int nSelection = m_ListBox.GetCurSel();
if (nSelection != LB_ERR) {
CString strValueName;
m_ListBox.GetText(nSelection, strValueName);
// Delete item from list box
m_ListBox.DeleteString(nSelection);
// Delete item from the registry
strKey = GetFilenameExtension(strFilename) + "\\MultiLaunch";
if (RegOpenKeyEx(HKEY_CLASSES_ROOT, strKey, 0, KEY_ALL_ACCESS,
&hKey) == ERROR_SUCCESS)
RegDeleteValue(hKey, strValueName);
// Delete item from our internal CRegistryKey list
pRegistryKey->RemoveAt(nSelection);
// If this is the last item in the list, remove the MultiLaunch key
if (pRegistryKey->GetCount() <= 1)
RegDeleteKey(HKEY_CLASSES_ROOT, strKey);
}
}
// Add a new association to the registry
void CMLPage::OnAdd()
{
HKEY hKey;
CString strKey;
DWORD Disposition;
// Execute this code only if we're not already displaying a dialog
if (!m_bOpenDialog) {
m_bOpenDialog = TRUE;
CFileDialog FileDialog(TRUE, "*.exe", NULL, OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST, "Executable Files(*.exe)|*.exe|COM Files(*.com)|*.com|");
if (FileDialog.DoModal() == IDOK) {
// Does item exist already in the list box?
if (m_ListBox.FindString(-1, FileDialog.GetFileTitle()) == LB_ERR) {
// Add item to list box
m_ListBox.AddString(FileDialog.GetFileTitle());
// Add item to the registry
strKey = GetFilenameExtension(strFilename) + "\\MultiLaunch";
if (RegOpenKeyEx(HKEY_CLASSES_ROOT, strKey, 0, KEY_ALL_ACCESS,
&hKey) == ERROR_SUCCESS)
CreateRegValue(hKey, FileDialog.GetFileTitle(), FileDialog.GetPathName());
else {
// Key did not exist already - create it
RegCreateKeyEx(HKEY_CLASSES_ROOT, strKey, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
&hKey, &Disposition);
CreateRegValue(hKey, FileDialog.GetFileTitle(), FileDialog.GetPathName());
}
}
}
m_bOpenDialog = FALSE;
}
}
// Display about box
void CMLPage::OnAboutbox()
{
if (!m_bAboutDialog) {
m_bAboutDialog = TRUE;
::MessageBox(0, "MultiLaunch V1.0\n\n(C)1996 By Ziff-Davis Publishing Company. All rights reserved.\nFirst appeared in PC Magazine, U.S. Edition, May 28, 1996.\n\nWritten by John Lam.", "About MultiLaunch", MB_OK);
m_bAboutDialog = FALSE;
}
}